// #include "rclcpp/rclcpp.hpp"
// #include <iostream>
// #include "std_msgs/msg/string.hpp"
// #include "std_msgs/msg/u_int32.hpp"
// using namespace std;

// class TalkerNode : public rclcpp::Node
// {
// public:
//     TalkerNode(string name):Node(name)
//     {
//         RCLCPP_INFO(this->get_logger(),"The talker node start success!");
//         pub_talker = this->create_publisher<std_msgs::msg::String>("talker_node",10);
//         timer_ = this->create_wall_timer(1ms,std::bind(&TalkerNode::recall_fun,this));
        
//     }
// private:
//     int count = 0;
//     rclcpp::Publisher<std_msgs::msg::String>::SharedPtr pub_talker;
//     rclcpp::TimerBase::SharedPtr timer_;
//     void recall_fun()
//     {
//         auto mes = std_msgs::msg::String();
//         mes.data = "I am talker,publishing message" + std::to_string(count);
//         pub_talker->publish(mes);
//         count += 1;
//     }
// };

// int main(int argc,char** argv)
// {
//     rclcpp::init(argc,argv);
//     auto node = std::make_shared<TalkerNode>("taker");
//     rclcpp::spin(node);
//     rclcpp::shutdown();
//     return 0;
// }

#include <chrono>
#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

using namespace std::chrono_literals;

/* This example creates a subclass of Node and uses std::bind() to register a
 * member function as a callback from the timer. */

class MinimalPublisher : public rclcpp::Node
{
public:
  MinimalPublisher()
  : Node("minimal_publisher"), count_(0)
  {
    publisher_ = this->create_publisher<std_msgs::msg::String>("topic", 10);
    timer_ = this->create_wall_timer(
      500ms, std::bind(&MinimalPublisher::timer_callback, this));
  }

private:
  void timer_callback()
  {
    auto message = std_msgs::msg::String();
    message.data = "Hello, world! " + std::to_string(count_++);
    RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.c_str());
    publisher_->publish(message);
  }
  rclcpp::TimerBase::SharedPtr timer_;
  rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
  size_t count_;
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<MinimalPublisher>());
  rclcpp::shutdown();
  return 0;
}